package dataStructure;

public class MainClass {
    public static void main(String[] args) {
//        Stack<String> stack = new Stack<>();
//        stack.push("hello");
//        stack.push(",");
//        stack.push("world");
//        stack.push("!");
//
//        System.out.println("空判断:" + stack.isEmpty());
//        System.out.println("满判断:" + stack.isFull());
//        System.out.println("元素个数:" + stack.size());
//        System.out.println("出栈元素:" + stack.pop());
//        System.out.println("获取栈顶元素:" + stack.top());

        /**
         * 空判断:false
         * 满判断:false
         * 元素个数:4
         * 出栈元素:!
         * 获取栈顶元素:world
         */

//        System.out.println(check("(A+B)+{[c-d]}"));

        //使用栈反向输出队列
        reverseQueue();
    }

    public static void reverseQueue() {
        Queue<String> queue = new Queue<>();
        queue.enQueue("h");
        queue.enQueue("e");
        queue.enQueue("l");
        queue.enQueue("l");
        queue.enQueue("o");

        //定义栈
        Stack<String> stack = new Stack<>();
        while (!queue.isEmpty()) {
            stack.push(queue.deQueue());
        }
        while (!stack.isEmpty()) {
            System.out.println(stack.pop());
        }
    }

    public static boolean check(String expression) {
        boolean res = true;
        //开分隔符,注意字符顺序对应
        String openCharacter = "([{";
        //闭分隔符
        String closeCharacter = ")]}";
        Stack<Character> sequenceStack = new Stack<>();

        for (Character c : expression.toCharArray()) {
            //如果开分隔符包含则入栈
            if (openCharacter.contains(c.toString())) {
                sequenceStack.push(c);
            } else if (closeCharacter.contains(c.toString())) {
                if (sequenceStack.isEmpty()) {
                    res = false;
                    break;
                } else {
                    //判断是否匹配
                    if (openCharacter.indexOf(sequenceStack.pop()) != closeCharacter.indexOf(c)) {
                        res = false;
                        break;
                    }
                }
            }
        }

        return res;
    }
}
